package ar.com.angrymachine.hunter.activities;

import ar.com.angrymachine.hunter.Activity;

public abstract class DecrementalActivity extends Activity
{
    protected DecrementalActivity(int initialTime)
    {
    	this.initialTime = initialTime;
        reset();
    }
    
    protected int initialTime;
    protected int currentTime;
    protected abstract int getFinalDecrement(int delta);
    protected abstract boolean onCompletion(); // returns if the activity should be removed
    
    public void reset()
    {
    	currentTime = initialTime;
    }
    
    public void update(int delta, boolean action, boolean timeIsRunning)
    {
        if(timeIsRunning)
        {
            currentTime -= getFinalDecrement(delta);
            if(currentTime <= 0)
            {
            	currentTime = 0;
                if(onCompletion())
                {
                	end(true);
                }
            }
        }
    }

    public boolean isCompleted()
    {
        return currentTime == 0;
    }
}
